<?php

/**
 * Created by PhpStorm.
 * User: 志俊
 * Date: 2015/5/28 0028
 * Time: 12:46
 */
class Keywords extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    //文件增加敏感词
    function input_keyword()
    {
        $config['upload_path'] = './public/file';
        $config['allowed_types'] = '*';
        $config['max_size'] = '10000';
        $this->load->library('upload', $config);

        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data = $error;
        } else {
            $text = $this->upload->data();
        }
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->input_badword($text['full_path']);
        echo json_encode($data);
//        $file=file($text['full_path']);
//        $i=0;
//        $j=0;
//        header("Content-type: text/html; charset=utf-8");
//        foreach($file as $line)
//        {
//            ++$i;
//            //echo json_encode($line);
//            $data[$i]=$line;
//        }
//        var_dump($data);
    }

    //增加敏感词
    function add_keyword()
    {
        $text = $this->input->post('text');
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->add_badword($text);
        echo json_encode($data);
    }

    //显示敏感词
    function show_keywords()
    {
        $page = $this->input->post('page');
        $limit = $this->input->post('limit');
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->show_keywords_list($page, $limit);
        echo json_encode($data);
    }

    //删除敏感词
    function del_keyword()
    {
        $Id = $this->input->post('Id');
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->delete_keywords($Id);
        echo json_encode($data);
    }

    //敏感词列表去重
    function sort_keyword()
    {
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->distinct_keywords();
        echo json_encode($data);
    }

    //敏感词修改
    function reset_keyword()
    {
        $Id = $this->input->post('Id');
        $text = $this->input->post('text');
        $this->load->model('Keywords_model', 'keywords', TRUE);
        $data = $this->keywords->update_keywords($Id, $text);
        echo json_encode($data);
    }
}